const MplModel = require('../models/matchplayers.js')

class MplCtrl {

    async list() {
        let lst = await MplModel.find();//.sort('eventId');
        return lst.map(m=>m.toJSON());
    }

    async create(MplData) {
        let mp = new MplModel(MplData);
        mp = await mp.save();
        return mp.toJSON();
    }

    async retrieve(id) {
        let mp = await MplModel.findById(id);
        return mp?mp.map(e=>e.toJSON()): null;
    }

    async upsert(id, MplData) {
        MplData.id = id;
        let mp = await MplModel.upsert(id, MplData);
        return mp.toJSON();
    }
    async removeById(id) {
        await MplModel.removeById(id);
        return 1;
    }

    async find(filter)
    {
        let r = await MplModel.find(filter);
        return r.map(e=>e.toJSON());
    }
}

module.exports = new MplCtrl();